package com.songtech.uitest.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


@Component
public class SumUpHelper {

    private Logger logger = LoggerFactory.getLogger(SumUpHelper.class);

    private List<String> flowErrorList = null;

    private List<String> retryList = null;

    private List<String> assertErrorList = null;


    public List<String> getFlowErrorList(){
        if(flowErrorList == null){
            flowErrorList = new ArrayList<String>();
        }
        return flowErrorList;
    }

    public List<String> getRetryList(){
        if(retryList == null){
            retryList = new ArrayList<String>();
        }
        return retryList;
    }

    public List<String> getAssertErrorList(){
        if(assertErrorList == null){
            assertErrorList = new ArrayList<String>();
        }
        return assertErrorList;
    }

    public void printResult(){
        //防止这三个属性为空
        getFlowErrorList();
        getAssertErrorList();
        getRetryList();

        logger.info("=====================本==流==程==测==试==结==果=====================");
        logger.info("共发生流程错误" + getFlowErrorList().size() + "次，重试了" + getRetryList().size() + "次，具体流程失败内容为：");
        logger.info("-------------------------------------------------------------------");
        Iterator<String> iterFlow = getFlowErrorList().iterator();
        while(iterFlow.hasNext()){
            logger.info(iterFlow.next().toString());
        }
        logger.info("-------------------------------------------------------------------");
        logger.info("共发生断言失败" + assertErrorList.size() + "次，具体断言失败内容为：");
        logger.info("-------------------------------------------------------------------");
        Iterator<String> iterAssert = assertErrorList.iterator();
        while(iterAssert.hasNext()){
            logger.info(iterAssert.next().toString());
        }
        logger.info("===================================================================");
    }

    public void clearResult(){
        flowErrorList.clear();
        retryList.clear();
        assertErrorList.clear();
    }
}
